<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">商家管理</h3>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">申请</div>
                    <div class="panel-body inner-body">
                       <div class="main-box-search">
                            <form method="get" name="from1"  id="searchForm"  >
                                <div class="search-row">
                                    <div class="col-lg-3 col-md-6" style=" margin-bottom:15px; padding-left:0px;">
                                        <input class="form-control" type="text" name="accountId" id="accountId"
                                               placeholder="请输入用户ID">
                                    </div>
                                    <div class="col-lg-2 col-md-6" style="margin-bottom:15px; padding-left:0px;">
                                        <select class="form-control" id="status">
                                            <option value="4">全部</option>
                                            <option value="0">未处理</option>
                                            <option value="2">未通过</option>
                                            <option value="1">已通过</option>
                                        </select>
                                	</div>
                                </div>
                                <%-- <a class="btn btn-primary" href="${webPath}toDiscussAdd"
                      style="margin-left:15px;margin-bottom:30px;">添加消费</a> --%>
                            </form>
                        </div>
        
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                <tr>
                                    <th class="id text-center" style="width:4%;">id</th>
                                    <th class="id text-center" style="width:4%;">用户id</th>
                                    <th class="id text-center" style="width:4%;">用户姓名</th>
                                    <th class="id text-center" style="width:4%;">手机号码</th>
                                    <th class="id text-center" style="width:4%;">店名</th>
                                    <th class="text-center" style="width:10%;">店铺图片</th>
                                    <th class="text-center" style="width:10%;">营业执照图片</th>
                                    <th class="id text-center" style="width:4%;">地址</th>
                                    
                                    <th class="displayId_info text-center" style="width:6%;">创建时间</th>
                                    <th class="operate text-center" style="width:10%;">操作</th>
                                </tr>
                                </thead>
                                <tbody id="unionList">
                                </tbody>
                            </table>
                        </div>
                        <div class="modal fade" id="sendModel">
                            <div class="modal-dialog">
                                <div class="modal-content message_align">
                                    <div class="modal-header">
                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                        <h4 class="modal-title">是否确定通过申请</h4>
                                    </div>
                                    <div class="modal-footer">
                                        <input id="id_hidden" type="hidden">
                                        <input id="accountId" type="hidden">
                                        <button class="btn btn-default" type="button" data-dismiss="modal">取消</button>
                                        <a class="btn btn-danger" onclick="agree()" data-dismiss="modal">确定</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="text-right">
                            <ul class="pagination" id="pagination">
                                <li><a href="javascript:void(0);" onclick="" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
				                <li><a  href="javascript:void(0);" onclick="" >1</a></li>
				                <li><a href="javascript:void(0);" onclick=""  aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
	var excelPage = 1;

	searchCase(0,1);
	$('#searchForm').change(function(e) {
		searchCase(1,1);
	})
	//搜索
	function searchCase(flag,page) {
		excelPage = page;
		var accountId = null;
		var unionId = null;
		
		var pageSize= 10;
		
		var startTime = null;
		var endTime = null;
		
		if(flag == 1){
			var startTime = $("#datetimepicker6").val();
			var endTime = $("#datetimepicker7").val();
			accountId = $("#accountId").val();
			status = $("#status").val();
			unionId = $("#unionId").val();
		}
		
		var baseURL = "${webPath}/union/list";
	    var json_package = {
	        "head": {},
	        "body": {
	        	"status": status,
	        	"accountId":accountId,
	            "page": page,
	            "pageSize": pageSize
	        }
	    }
	    $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	        if (typeof result == 'string') result = JSON.parse(result);
	        if (result.body.result == '1') {
	            alert(result.body.description)
	            $("#unionList").empty();
	        } else {
	        	$("#unionList").empty();
	        	var list = result.body.list;
	        	var count = result.body.count;
	        	var str = "";
	        	if(list.length<=0){
	        		return
	        	}
	        	for(var i=0;i<list.length;i++){
	        		str += '<tr>';
	        		str += '	<td class="text-center">'+list[i].id+'</td>';
	        		str += '	<td class="text-center">'+list[i].accountId+'</td>';
	        		str += '	<td class="text-center">'+list[i].name+'</td>';
	        		str += '	<td class="text-center">'+list[i].phone+'</td>';
	        		str += '	<td class="text-center">'+list[i].unionName+'</td>';
	        		str += '	<td class="coverImg"><img class="center-block" src="'+list[i].image+'"></td>';
	        		str += '	<td class="coverImg"><img class="center-block" src="'+list[i].proveImage+'"></td>';
	        		str += '	<td class="text-center">'+list[i].address+'</td>';
	        		str += '	<td class="text-center">'+list[i].createTime+'</td>';
	        		str += '	<td class="text-center">';
					if(0 == list[i].status){
						str += '		<button class="btn btn-default  deliver_goods" onclick=send('+list[i].id+','+list[i].accountId+')>通过</button>';
						str += '		<button class="btn btn-default  deliver_goods" onclick=faild('+list[i].id+','+list[i].accountId+')>拒绝</button>';
					}else if(1 == list[i].status){
						str +='<span>已经通过</span>';
					}else if(2 == list[i].status){
						str +='<span>已经拒绝</span>';
					}
					str += '	</td>';
	        		str += '</tr>';
	        	}
	        	$("#unionList").append(str);
	        	
	        	$("#pagination").empty();
	        	var pageString = "";
	        	var currentPage = page;
	        	var sumPage = Math.ceil(count/pageSize);
	        	pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+(currentPage-1)+') aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>';
	        	for(var i=1;i<=sumPage;i++){
	        		if(currentPage == i){
        				pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+i+') class="active">'+i+'</a></li>';
        			}else{
        				pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+i+')>'+i+'</a></li>';
        			}
	        	}
	        	if(sumPage==currentPage){
	        		pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+(currentPage)+') aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>';
	        	}else{
	        		pageString += '<li><a href="javascript:void(0);" onclick=searchCase(1,'+(currentPage+1)+') aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>';
	        	}
	        	
	        	$("#pagination").append(pageString);
	        }
	    })
	}
		
	function send(id,accountId) {
        $('#sendModel').modal();
        $("#id_hidden").val(id);
        $("#accountId").val(accountId);
        
    }
	
	var agree = function () {
        var baseURL = "${webPath}/union/deal";
        var id = $("#id_hidden").val();
        var accountId =$("#accountId").val();
        var json_package = {
            "head": {},
            "body": {"id": id, "type": 1,"accountId":accountId}
        };
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                alert(result.body.description);
                searchCase(1,excelPage);
            } else {
                alert(result.body.description)
            }
        })
    };
	
    function faild(id) {
    	var flag = confirm("是否确认拒绝商家申请");
    	if(flag == true){
    		var baseURL = "${webPath}/union/deal";
            var json_package = {
                "head": {},
                "body": {"id": id, "type": 0}
            };
            $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
                if (typeof result == 'string') result = JSON.parse(result);
                if (result.body.result == '0') {
                    alert(result.body.description);
                    searchCase(1,excelPage);
                } else {
                    alert(result.body.description)
                }
            })
    	}
    };
    
    function delCash(r) {
        $("table").index($(r).parent().parent());
        $(r).parent().parent().remove();
    }
    $(function () {
        $('#datetimepicker6').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss'
        });
        $('#datetimepicker7').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss'
        });
        $('#datetimepicker6').datetimepicker();
        $('#datetimepicker7').datetimepicker({
            useCurrent: false //Important! See issue #1075
        });
        $("#datetimepicker6").on("dp.change", function (e) {
            $('#datetimepicker7').data("DateTimePicker").minDate(e.date);
        });
        $("#datetimepicker7").on("dp.change", function (e) {
            $('#datetimepicker6').data("DateTimePicker").maxDate(e.date);
        });
    });
    
    $(document).ready(function () {
        var lenth = $('#unionList tr').length;
        if (lenth == 0) {
            $('tbody#unionList').append('<tr id="empty_menu"><td colspan="9" class="no-menu text-center">没有申请信息！</td></tr>');
        } else {
            $('#empty_menu').hide();
        }
    })
    
</script>
</body>
</html>
